<template>
  <header>
    <div class="left">
      <el-button plain icon="el-icon-menu" size="mini" @click="toogleCollapse"></el-button>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item @click="toPage({ path: '/' })">首页</el-breadcrumb-item>
        <el-breadcrumb-item @click="toPage(currentMenu)" v-if="currentMenu">{{ currentMenu.label }}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="right">
      <el-dropdown trigger="click" size="mini">
        <span class="el-dropdown-link"> <img :src="userImg" alt="头像不见了" /> </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>个人中心</el-dropdown-item>
          <el-dropdown-item @click.native="logOut">退出</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </header>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
export default {
  computed: {
    ...mapState({
      currentMenu: (state) => state.tab.currentMenu,
    }),
  },
  data() {
    return {
      userImg: require('@/assets/images/user.png'),
    }
  },
  methods: {
    ...mapMutations(['toogleCollapse']),
    toPage(val) {
      if (this.$router.currentRoute.fullPath !== val.path) {
        this.$router.push({ name: val.name })
      }
    },
    logOut() {
      this.$store.commit('clearToken')
      this.$store.commit('clearMenu')
      location.reload()
    },
  },
}
</script>

<style lang="scss" scoped>
header {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.left {
  display: flex;
  align-items: center;
  button {
    margin-right: 20px;
  }
}
.right {
  img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }
}
</style>
